const app = new Vue({
        el: '#app',
        data: {
            books: [
                {
                    id: 1,
                    name: 'Java基础',
                    data: '2006-4',
                    price: 50.60,
                    count: 1,
                },
                {
                    id: 2,
                    name: 'SpringBoot',
                    data: '2007-4',
                    price: 68.60,
                    count: 1,
                },
                {
                    id: 3,
                    name: 'Android Studio开发',
                    data: '2009-4',
                    price: 70.60,
                    count: 1,
                },
                {
                    id: 4,
                    name: 'HTML+CSS+jQuery',
                    data: '2010-4',
                    price: 70.80,
                    count: 1,
                },
                {
                    id: 5,
                    name: 'C# .NET',
                    data: '2012-4',
                    price: 69.70,
                    count: 1,
                },

            ],
        },
        methods: {
            decrement(index) {
                this.books[index].count++;
            },
            increment(index) {
                this.books[index].count--;
            },
            removeHandle(index) {
                this.books.splice(index,1)
            },
        },
        computed: {
            totalPrice() {
                // let totalPrice = 0;
                // for (let i = 0; i< this.books.length; i++) {
                //     totalPrice += this.books[i].price * this.books[i].count;
                // }
                // return totalPrice;

                //for(let i in this.books)
                // let totalPrice = 0;
                // for (let i in this.books){
                //     totalPrice += this.books[i].price * this.books[i].count;
                // }
                // return totalPrice;

                // let totalPrice = 0;
                // for (let item of this.books){
                //     totalPrice += item.price * item.count;
                // }
                // return totalPrice;

                return this.books.reduce(function (preValue, book) {
                    return preValue + book.price * book.count;
                }, 0)
            }
        },
        filters: {
            showPrice(price) {
                return '￥' + price.toFixed(2);
            }
        }
    })